package com.szrt.java.day20170109.demo04;


import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.junit.Test;

/**
 * 凡是能干活的都是new出来的类的对象
 * @author zsrt
 *
 */
public class CollectionTest {

	@Test
	public void setTest() {
		
		Set<String> set = new HashSet<String>();
		
		set.add("AA");
		set.add("BB");
		set.add("CC");
		set.add("AA");
		
		int size = set.size();
		System.out.println("set集合的size()为："+size);
		
		Iterator<String> it = set.iterator();
		
		while(it.hasNext()){
			String str = it.next();
			System.out.println(str);
		}
		
	}
	
	public boolean add(List<String> addList,String addData){
		
		//int counter = 0;
		for(int i =0;i<addList.size();i++){
			
			if(addList.get(i).equals(addData)){
				System.out.println("输入数据不能重复，添加失败...");
				System.out.println("输入数据与集合中第"+(i+1)+"个数据重复,重复数据为："+addData);
				//counter = counter + 1;
				//break;
				return false;
			}
			/*if(counter == 0){
				list.add(list, data);
			}*/
		}
		
		return addList.add(addData);
	}
	
	@Test
	public void listTest() {
		
		List<String> list = new ArrayList<String>();
		
		add(list,"AA");
		add(list,"BB");
		add(list,"CC");
		add(list,"AA");
		
		for(int i =0;i<list.size();i++){
			System.out.println(list.get(i));
		}
		
	}
	
}
